
<?php
$this->breadcrumbs=array(
	'Event Management ',
);
?>    
<div>
    <div class="pull-right">
        <div class="widget-toolbar">
            			
            <a href="<?php echo Yii::app()->createAbsoluteUrl($parentUrl . '/create'); ?>" role="button" class="white" data-toggle="modal"  title="Add new category">
                <i class="icon-plus"></i>
            </a>
        </div>
    </div>
</div>
<div class="row-fluid">
    <div class="row-fluid">
        <div class="table-header">
            Event Management
            <div class="row-fluid">
                <div class="today">
                    <?php
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'event-form',
            'enableAjaxValidation' => false,
            'enableClientValidation' => true,
            'htmlOptions' => array(
                'class' => 'form-horizontal',
                 'enctype' => 'multipart/form-data'
            ),
        ));
    ?>
            <select id="form-field-select-1" class="change-view" name="status">
                <?php if(isset($status)){ ?>
                    <?php if($status == STATUS_ACTIVE) { ?>
                        <option value="<?php echo STATUS_ACTIVE; ?>" selected="selected">Opening</option>
                        <option value="<?php echo STATUS_EXPIRED; ?>">Expired</option>
                    <?php }else{ ?>
                        <option value="<?php echo STATUS_ACTIVE; ?>" >Opening</option>
                        <option value="<?php echo STATUS_EXPIRED; ?>" selected="selected">Expired</option>
                    <?php }?>
                <?php } ?>
            </select>
    <?php $this->endWidget(); ?>
                </div>
            </div>
        </div>
        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>Event code</th>
                    <th>Main title</th>
                    <th>Category</th>
                    <th>Gallery</th>
                    <th>Status</th>
                    <!--Danh cho icon-->
                    <th></th>
                    <!--Danh cho icon--> 
                </tr>
            </thead>
            <tbody>
                <?php
                if (count($data) > 0):
                    foreach ($data as $item) :
                        ?> 
                        <tr>
                            <td><?php echo $item->event_code ?> </td>
                            <td><?php echo $item->translate[1]['main_title'];  ?> </td>
                            <td><?php echo $item->category->name ?> </td>
                            <td>
                                <?php if(isset($item->gallery)) : ?>
                                    <?php echo $item->gallery->name ?>
                                <?php else : ?>
                                    Null, Please update
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php switch ($item->status) :
                                    case 1:
                                ?>
                                    <span class="label label-success">Openning</span>
                                <?php break;?>
                                <?php default :?>
                                    <span class="label label-default">Expried</span>
 
                                <?php break; ?>
                                <?php endswitch; ?>
                                <?php switch ($item->active_status) :
                                    case 1:
                                ?>
                                    <a class="label label-success" onclick="in_active_status(<?php echo $item->id; ?>)">
                                            Active
                                    </a>
                                <?php break;?>
                                <?php case 0: ?>
                                    <a class="label label-warning" onclick="active_status(<?php echo $item->id; ?>)">
                                            Inactive
                                    </a>
                                <?php break;?>
                                <?php default :?>
                                    <a class="label label-warning" onclick="active_status(<?php echo $item->id; ?>)">
                                            Inactive
                                    </a> 
                                <?php break; ?>
                                <?php endswitch; ?>
                            </td>
                            <!--Danh cho icon-->
                            <td class="td-actions">
                                <div class="hidden-phone visible-desktop action-buttons">
                                    
                                    <a class="green" href="<?php echo Yii::app()->createAbsoluteUrl($parentUrl . '/update', array('id' => $item->id)); ?>">
                                        <i class="icon-pencil bigger-130"></i>
                                    </a>
                                    <?php 
                                           echo CHtml::link(
                                                '',
                                                 array('event/delete','id'=>$item->id),
                                                 array('confirm' => 'Are you sure you want to delete this item?', 'class'=>'red')
                                            ); 
                                    ?>         
                                    <!--<i class="icon-trash bigger-130"></i>-->
<!--                                    <a class="red" href="<?php echo Yii::app()->createAbsoluteUrl($parentUrl . '/delete', array('id' => $item->id)); ?>">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>-->
                                </div>
                                <div class="hidden-desktop visible-phone">
                                    <div class="inline position-relative">
                                        <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                            <i class="icon-caret-down icon-only bigger-120"></i>
                                        </button>
                                        <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                            
                                            <li>
                                                <a href="<?php echo Yii::app()->createAbsoluteUrl($parentUrl . '/update', array('id' => $item->id)); ?>" class="tooltip-success" data-rel="tooltip" title="Edit">
                                                    <span class="green">
                                                        <i class="icon-edit bigger-120"></i>
                                                    </span>
                                                </a>
                                            </li>
                                            <li>
                                                <!--<a href="<?php // echo Yii::app()->createAbsoluteUrl($parentUrl . '/delete', array('id' => $item->id)); ?>" class="tooltip-error" data-rel="tooltip" title="Delete">-->
                                                <?php 
                                                CHtml::link(
                                                    'Delete',
                                                     array('event/delete','id'=>$item->id),
                                                     array('confirm' => 'Are you sure?')
                                                ); 
                                                ?>                                                
                                                    <span class="red">
                                                        <i class="icon-trash bigger-120"></i>
                                                    </span>
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </td>
                            <!--Danh cho icon-->
                        </tr>
                    <?php endforeach;
                endif; ?>                                    
            </tbody>
        </table>
    </div>
</div><!--/.row-fluid-->

<script type="text/javascript">
    $(document).ready(function(){
        $('.action-buttons').each(function(){
            $(this).find('a').eq(1).append('<i class="icon-trash bigger-120"></i>');
        });
        $('.change-view').change(function(){
            $('#event-form').submit();
        });
    });
    
    function active_status(event_id){
        $.ajax({
            url: '<?php echo Yii::app()->createAbsoluteUrl("bookingsystem/event/active"); ?>',
            type: 'POST',
            data: {event_id:event_id},
            beforeSend: function(){
                $('.row-fluid').empty();
                $('.row-fluid').append('<div class="loading"><div style="width:134px;height:100px;margin:0 auto;padding-top: 10px;"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/images/ajaxloader.gif"></div></div>');
            },
            success: function(data){
                window.location.reload();
            }
        });
    }
    function in_active_status(event_id){
        $.ajax({
            url: '<?php echo Yii::app()->createAbsoluteUrl("bookingsystem/event/inactive"); ?>',
            type: 'POST',
            data: {event_id:event_id},
            beforeSend: function(){
                $('.row-fluid').empty();
                $('.row-fluid').append('<div class="loading"><div style="width:134px;height:100px;margin:0 auto;padding-top: 10px;"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/images/ajaxloader.gif"></div></div>');
            },
            success: function(data){
                window.location.reload();
            }
        });
    }
</script>
<style>

    .today {
        position: absolute;
        right: 60px;
        top: 49px;
    }

    .today input{
        width: 100px;
    }

    .icon-calendar{
        /*background-color: black;*/
    }

    .add-on i{
        color: black;
    }
</style>